Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
Unit test -> Sinon + fluent-ffmpeg

I need some help with the following code:

const ffmpeg = require('fluent-ffmpeg'),
{PassThrough} = require('stream');

ffmpeg.setFfmpegPath('/opt/bin/ffmpeg');
ffmpeg.setFfprobePath('/opt/bin/ffprobe');

exports.wavCompilation = async (wavObjList, s3OutputFullPath) => {
    let command = ffmpeg();
    return new Promise(async (resolve, reject) => {

        const pt = new PassThrough()
        command
            .complexFilter(complexFilterList)
            .audioFrequency(44100)
            .audioChannels(2)
            .outputOptions('-map [audio]')
            .toFormat("wav")
            .output(pt, {end: true})
            .on('error', function (err, stdout, stderr) {
                console.log("stdout:\n" + stdout);
                console.log("stderr:\n" + stderr);
                if (err) {
                    console.log(err.message);
                    return reject("Error");
                }
            })
            .on('start', (commandLog) => printLog(commandLog))
            .on(`end`, () => console.info("end ffmpeg"))
            .run()

        resolve(***);
    });
}

Does anyone know how can I stub/mock/spy/fake "ffmpeg" ?

I use Sinon for unit tests and I'm trying to use proxyquire to mock "fluent-ffmpeg"

const sinon = require('sinon'),
proxyquire = require('proxyquire').noCallThru();

let ffmpegStub = {
    setFfmpegPath: () => {},
    setFfprobePath: () => {}
}

const ffmpegService = proxyquire('../services/ffmpeg-service/index', {
    'fluent-ffmpeg': ffmpegStub
});

for the methods setFfmpegPath and setFfprobePath it works but for the line:

let command = ffmpeg();

it says "ffmpeg is not a function"

I tried to add a default function such as:

let ffmpegStub = {
    default: () => {},
    setFfmpegPath: () => {},
    setFfprobePath: () => {}
}

but it also doesn't work and I have no idea now what I could do.

Please I need some fresh ideas, my goal is to catch the argument for "complexFilter" and assert it.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No need of proxyquire.

I've got what I wanted with the following:

filterStub = sandbox.stub(ffmpeg.prototype, "complexFilter").returnsThis();
sandbox.stub(ffmpeg.prototype, "run").returnsThis();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!